#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include "cpt.h"

void test_policy_ct_encrypt(unsigned char *instr, Policy *policy, unsigned char *outstr) {

    printf("instr:%s\n", instr);
    unsigned char *ip = instr;

    unsigned char *op = outstr;
    for (; *ip != '\0';) {
        *op++ = *ip++;
    }
    *op = '\0';

    printf("outstr:%s\n", outstr);

    int maxLen = policy->sub_policy_num;

    for (int i = 0; i < maxLen; i++) {
        SubPolicy *subPolicy = policy->subPolicy[i];
        int cPos = subPolicy->position;
        int cLen = subPolicy->length;

        /*memcpy(&cPos, &(subPolicy->position), 1);
        memcpy(&cLen, &(subPolicy->length), 1);*/

        printf("id: %d position=%d length=%d\n", i, cPos, cLen);
        printf("id:%d\n", i);
    }

    printf("I don't print\n");

}



//结构体函数
void NewSUB_POLICY(SubPolicy *subPolicy, int position, int length) {
    subPolicy->position = position;
    subPolicy->length = length;
}

void NewPOLICY(Policy *policy) {
    policy->sub_policy_num = 0;
}

void addSUB_POLICY(Policy *policy, SubPolicy *subPolicy) {
    policy->subPolicy[policy->sub_policy_num] = subPolicy;
    policy->sub_policy_num = policy->sub_policy_num + 1;
}

void outputPolicyDetail(Policy *policy) {
    for (int i = 0; i < policy->sub_policy_num; i++) {
        printf("id: %d, position=%d,length=%d\n", i, policy->subPolicy[i]->position, policy->subPolicy[i]->length);
    }
}

